﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core;
using Cofe.Core.Property;
using Cofe.Core.Utils;

namespace Cofe.Data
{
    public class DatabasePropertyFilter : IPropertyFilter
    {
        public DatabasePropertyFilter(DatabaseCacheOptions cacheOptions)
        {
            CacheOptions = cacheOptions;
        }

        public DatabaseCacheOptions CacheOptions { get; set; }

        public bool Match(object property)
        {
            DatabaseCacheOptions cacheOptions = DatabaseCacheOptions.NotCachable;
             var ca = AttributeUtils<CachableAttribute>.FindAttribute(property);
             if (ca != null)
                 cacheOptions = ca.DatabaseCacheOptions;
             
            return cacheOptions == CacheOptions;

        }
    }
}
